﻿using System;
using System.Collections.Generic;

namespace ShortestPaths
{
    public class EdgeWeightedDigraph
    {
        private int v;//顶点总数
        private int e;//边的总数
        private List<DirectedEdge>[] adj;//邻接表

        public EdgeWeightedDigraph(int v)
        {
            this.v = v;
            this.e = 0;
            adj = new List<DirectedEdge>[v];

            for (int i = 0; i < v; i++)
            {
                adj[i] = new List<DirectedEdge>();
            }
        }

        public int V()
        {
            return v;
        }

        public int E()
        {
            return e;
        }

        public void AddEdge(DirectedEdge _e)
        {
            adj[_e.From()].Add(_e);
            e++;
        }

        public IEnumerable<DirectedEdge> Adj(int v)
        {
            return adj[v];
        }

        public IEnumerable<DirectedEdge> Edges()
        {
            List<DirectedEdge> edges = new List<DirectedEdge>();
            foreach (var _adj in adj)
            {
                edges.AddRange(_adj);
            }

            return edges;
        }
    }
}
